#include "CF_Core.h"

CCF_Log::CCF_Log()
{
  this->m_bEnable = false;
}

//-----------------------------------------------------------------------------
CCF_Log::~CCF_Log()
{
  this->EndLogging();
}
//-----------------------------------------------------------------------------
// Name: XLogError(char *lpszText, ...)
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::LogError(LPSTR lpszText, ...)
{
  if(m_bEnable)
  {
    va_list argList;

    //Initialize variable argument list
    va_start(argList, lpszText);

    //Write the error to the log file
    fprintf(m_logFile, "<font face=\"Arial\" size=\"2\" color=\"#FF0000\"><b>");
    vfprintf(m_logFile, lpszText, argList);
    fprintf(m_logFile, "</b></font><br>\n");

    va_end(argList);
  }
}
//-----------------------------------------------------------------------------
// Name: XWriteToLog(char *lpszText, ...)
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::WriteToLog(LPSTR lpszText, ...)
{
  if(m_bEnable)
  {
    va_list argList;

    //Initialize variable argument list
    va_start(argList, lpszText);

    //Write the error to the log file
    fprintf(m_logFile, "<font face=\"Arial\" size=\"2\" color=\"#000000\">");
    vfprintf(m_logFile, lpszText, argList);
    fprintf(m_logFile, "</font><br>\n");

    va_end(argList);
  }
}
//-----------------------------------------------------------------------------
// Name: XLogWarning(char *lpszText, ...)
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::LogWarning(LPSTR lpszText, ...)
{
  if(m_bEnable)
  {
    va_list argList;

    //Initialize variable argument list
    va_start(argList, lpszText);

    //Write the error to the log file
    fprintf(m_logFile, "<font face=\"Arial\" size=\"2\" color=\"#E7651A\"><b>");
    vfprintf(m_logFile, lpszText, argList);
    fprintf(m_logFile, "</b></font><br>\n");

    va_end(argList);
  }
}
//-----------------------------------------------------------------------------
// Name: XBeginLogging()
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::BeginLogging( const LPSTR logFile )
{
  if( !m_bEnable )
  {
    m_logFile = fopen( logFile, "wb" );

    if(m_logFile != NULL)
    {
      m_bEnable = true;

      fprintf(m_logFile, "<html><head><title>Log File</title></head><body>\n");
      fprintf(m_logFile, "<font face=\"Arial\" size=\"4\" color=\"#000000\"><b><u>Log File</u></b></font><br>\n");
    }
    else
    {
      m_bEnable = true;
    }
  }
}
//-----------------------------------------------------------------------------
// Name: XEndLogging()
// Desc: Logging
//-----------------------------------------------------------------------------
void CCF_Log::EndLogging()
{
  if(m_bEnable)
  {
    fprintf(m_logFile, "</body></html>");
    fclose(m_logFile);
    m_bEnable = false;
  }
}
